package 多线程.多线程;

public class Synchronized {
    public static void main(String[] args) {
        Object lock = new Object();
        Thread t1 = new Thread(() ->{
            synchronized (lock){
                for (int i = 0; i < 8; i++) {
                    System.out.println("线程1");
                    try {
//                        lock.wait();//线程从运行态转为阻塞态
                        Thread.yield();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

        });
        Thread t2 = new Thread(() -> {
            while (true){
                    System.out.println("线程222222222");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    lock.notify();//线程唤醒
                }
        });
        t1.start();
        t2.start();
    }
}
